//https://leetcode.cn/problems/invert-binary-tree/

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */

//辅助函数
void _invertTree(struct TreeNode* root){
    //空树
    if(root==NULL){
        return;
    }

    //左右节点非空，交换
    if(root->left || root->right){
        struct TreeNode* temp=root->left;
        root->left=root->right;
        root->right=temp;
    }

    //递归
    _invertTree(root->left);
    _invertTree(root->right);
}



 //问题原函数
struct TreeNode* invertTree(struct TreeNode* root) {
    _invertTree(root);
    return root;
}